package 神奇数;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    static int N = 110, cnt;
    static int[] pr = new int[N];
    static boolean[] st = new boolean[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int res = 0;
        find();
        for (int i = a; i <= b; i++) {
            res += check(i);
        }
        System.out.println(res);
    }

    private static void find() {
        st[1] = true;
        for (int i = 2; i < 100; i++) {
            if (!st[i]) {
                pr[cnt++] = i;
            }
            for (int j = 0; pr[j] <= 100 / i; j++) {
                st[pr[j] * i] = true;
                if (i % pr[j] == 0) {
                    break;
                }
            }
        }
    }

    private static int check(int x) {
        int[] num = new int[10];
        int n = 0;
        while (x > 0) {
            num[n++] = x % 10;
            x /= 10;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j && num[i] != 0) {
                    if (!st[num[i] * 10 + num[j]]) {
                        return 1;
                    }
                }
            }
        }
        return 0;
    }
}